package net.stock.controller;

import net.stock.service.StockService;
import net.stock.utils.StockUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.logging.Logger;
import java.util.logging.Level;
import java.io.IOException;

/**
 * @author naim
 * @date Jan 7, 2010
 */
@Controller("/_ah/xmpp/message/chat/")
public class XMPPMessageReceiver {
    private Logger log = Logger.getLogger(getClass().getName());

    @Autowired
    private StockService stockService;

    @RequestMapping(method = RequestMethod.POST)
    public ModelAndView post(HttpServletRequest request, HttpServletResponse response) throws IOException {
        log.log(Level.INFO, "in XMPPMessageReceiver");
        stockService.processMessage(request);
        StockUtils.writeToResponseOutputStream(response, "XMPP Message processed");
        return null;
    }
}
